<?php
// $view = file_get_contents("http://gw.api.taobao.com/router/rest?sign=FF745C14F0CF947E5279CBEDFF06DA58&timestamp=2012-07-30+13%3A27%3A12&v=2.0&app_key=12479925&method=taobao.shop.get&partner_id=top-apitools&format=json&nick=%E7%9A%87%E5%AE%B6%E5%AE%9D%E8%B4%9D%E6%97%97%E8%88%B0&fields=sid,cid,title,nick,desc,bulletin,pic_path,created,modified");

require './top/TopClient.php';
require './top/RequestCheckUtil.php';
require './top/Logger.php';
require './top/request/ItemGetRequest.php';
require './top/request/TaobaokeItemsConvertRequest.php';
$TopClient = new TopClient();
$TopClient->appkey = "21087743";
$TopClient->secretKey = "5f0cf1f8200d4854cb87410620878159";
$TopClient->format="json";
$TaobaokeItemsConvertRequest = new TaobaokeItemsConvertRequest();
$TaobaokeItemsConvertRequest->setFields(
        "click_url,num_iid,commission,commission_rate,commission_num,commission_volume");
$TaobaokeItemsConvertRequest->setNick("douqin2010");
$TaobaokeItemsConvertRequest->setPid(32295788);

// $view= json_decode($view);
include 'dom.php';
$taobaoSid= 33931656;
$shopUrl = "http://handuyishe.tmall.com/";
$itme = file_get_html($shopUrl."search.htm?search=y&viewType=list&orderType=_hotsell&pageNum=1");
// $itme = file_get_html("http://shop$taobaoSid.taobao.com/search.htm?search=y&viewType=list&orderType=_hotsell&pageNum=1");
$Pages= substr($itme->find(".page-info",0)->innertext(), 2);

for ($page = 1; $page < $Pages; $page++) {
    $itme = file_get_html($shopUrl."search.htm?search=y&viewType=list&orderType=_hotsell&pageNum=".$page);
    foreach ($itme->find(".shop-hesper-bd .item ") as $k=>$it){
//         print_r($it->find("a",1)->href);
        $url = parse_url($it->find("a",1)->href);
        parse_str($url['query'], $urlout);
        $CacheId =($urlout['id']);
        $TaobaokeItemsConvertRequest->setNumIids($CacheId);
        $TBCache = $TopClient->execute($TaobaokeItemsConvertRequest);
        print_r($TBCache);
        sleep(1);
        echo "\n";
    }
}









// $c = new TopClient();
// $c->appkey = "12479925";
// $c->secretKey = "d096667e2150d2e03c21eb5ac498ce7e";
// $req = new TopatsItemcatsGetRequest();
// $req->setSellerType("B");
// $req->setCids("0");
// $req->setOutputFormat("json");
// $resp = $c->execute($req);

// print_r($resp);
